/***************************************************************
 * Name:      MonkeywrenchMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    FoxBlitzz (danhagerstrand@gmail.com)
 * Created:   2008-12-11
 * Copyright: FoxBlitzz ()
 * License:
 **************************************************************/

#include "MonkeywrenchMain.h"
#include "ZonePanel.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(MonkeywrenchFrame)
#include <wx/artprov.h>
#include <wx/bitmap.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(MonkeywrenchFrame)
const long MonkeywrenchFrame::idMainNotebook = wxNewId();
const long MonkeywrenchFrame::idMenuNewResource = wxNewId();
const long MonkeywrenchFrame::idMenuNewZone = wxNewId();
const long MonkeywrenchFrame::idMenuNewObject = wxNewId();
const long MonkeywrenchFrame::idMenuNewActor = wxNewId();
const long MonkeywrenchFrame::idMenuNewTileset = wxNewId();
const long MonkeywrenchFrame::idMenuNewPicfile = wxNewId();
const long MonkeywrenchFrame::idMenuNewSoundfile = wxNewId();
const long MonkeywrenchFrame::idMenuNewSettings = wxNewId();
const long MonkeywrenchFrame::idMenuNew = wxNewId();
const long MonkeywrenchFrame::idMenuOpen = wxNewId();
const long MonkeywrenchFrame::idMenuClose = wxNewId();
const long MonkeywrenchFrame::idMenuSave = wxNewId();
const long MonkeywrenchFrame::idMenuSaveAs = wxNewId();
const long MonkeywrenchFrame::idMenuTest = wxNewId();
const long MonkeywrenchFrame::idMenuTestPosition = wxNewId();
const long MonkeywrenchFrame::idMenuCloseAll = wxNewId();
const long MonkeywrenchFrame::idMenuQuit = wxNewId();
const long MonkeywrenchFrame::idMenuCut = wxNewId();
const long MonkeywrenchFrame::idMenuCopy = wxNewId();
const long MonkeywrenchFrame::idMenuPaste = wxNewId();
const long MonkeywrenchFrame::idMenuDelete = wxNewId();
const long MonkeywrenchFrame::idMenuSelectAll = wxNewId();
const long MonkeywrenchFrame::idMenuSelectNone = wxNewId();
const long MonkeywrenchFrame::idMenuAbout = wxNewId();
const long MonkeywrenchFrame::ID_STATUSBAR1 = wxNewId();
const long MonkeywrenchFrame::ID_TOOLBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(MonkeywrenchFrame,wxFrame)
    //(*EventTable(MonkeywrenchFrame)
    //*)
END_EVENT_TABLE()

MonkeywrenchFrame::MonkeywrenchFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(MonkeywrenchFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, id, _("Monkeywrench"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(960,646));
    SetMinSize(wxSize(400,400));
    MainNotebook = new wxNotebook(this, idMainNotebook, wxPoint(256,224), wxDefaultSize, wxNB_TOP|wxNB_NOPAGETHEME, _T("idMainNotebook"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem3 = new wxMenu();
    MenuItem14 = new wxMenuItem(MenuItem3, idMenuNewResource, _("Resource...\tCtrl-N"), _("Creates a new, blank resource of your choosing: zonefile, objectdef, actordef, tileset, picfile, or soundfile."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem14);
    MenuItem3->AppendSeparator();
    MenuItem15 = new wxMenuItem(MenuItem3, idMenuNewZone, _("Zonefile"), _("Creates a zonefile, which represents a level or screen within the game."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem15);
    MenuItem16 = new wxMenuItem(MenuItem3, idMenuNewObject, _("Objectdef"), _("Creates an objectdef, which is a list of object properties to be used for a zonefile."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem16);
    MenuItem17 = new wxMenuItem(MenuItem3, idMenuNewActor, _("Actordef"), _("Creates an actordef, which is a collection of animations and sequences corresponding to a single entity."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem17);
    MenuItem18 = new wxMenuItem(MenuItem3, idMenuNewTileset, _("Tileset"), _("Creates a tileset, which is a list of tiles to be used as background layers, and their definitions."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem18);
    MenuItem19 = new wxMenuItem(MenuItem3, idMenuNewPicfile, _("Picfile"), _("Creates a picfile, which is an archive of graphics for use with actors and tilesets."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem19);
    MenuItem20 = new wxMenuItem(MenuItem3, idMenuNewSoundfile, _("Soundfile"), _("Creates a soundfile, which is an archive of sound effects used by actors or the game system."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem20);
    MenuItem3->AppendSeparator();
    MenuItem21 = new wxMenuItem(MenuItem3, idMenuNewSettings, _("Settingsfile"), _("Creates a settingsfile, which is used for a single game\'s initialization."), wxITEM_NORMAL);
    MenuItem3->Append(MenuItem21);
    Menu1->Append(idMenuNew, _("New"), MenuItem3, wxEmptyString);
    MenuItem4 = new wxMenuItem(Menu1, idMenuOpen, _("Open...\tCtrl-O"), _("Loads a resource file from disk."), wxITEM_NORMAL);
    Menu1->Append(MenuItem4);
    MenuItem5 = new wxMenuItem(Menu1, idMenuClose, _("Close\tCtrl-W"), _("Closes the current resource file, removing it from the workspace."), wxITEM_NORMAL);
    Menu1->Append(MenuItem5);
    MenuItem6 = new wxMenuItem(Menu1, idMenuSave, _("Save\tCtrl-S"), _("Saves a resource file under the current filename."), wxITEM_NORMAL);
    Menu1->Append(MenuItem6);
    MenuItem7 = new wxMenuItem(Menu1, idMenuSaveAs, _("Save As...\tF12"), _("Saves a resource file under a new filename."), wxITEM_NORMAL);
    Menu1->Append(MenuItem7);
    Menu1->AppendSeparator();
    MenuItem23 = new wxMenuItem(Menu1, idMenuTest, _("Test Zone\tCtrl-R"), _("Runs the active zone document in the game engine."), wxITEM_NORMAL);
    Menu1->Append(MenuItem23);
    MenuItem24 = new wxMenuItem(Menu1, idMenuTestPosition, _("Test Zone at Position...\tCtrl-Shift-R"), _("Runs the active zone document in the game engine, starting the player at a specified position."), wxITEM_NORMAL);
    Menu1->Append(MenuItem24);
    Menu1->AppendSeparator();
    MenuItem22 = new wxMenuItem(Menu1, idMenuCloseAll, _("Close All\tCtrl-Shift-W"), _("Closes all resource files, removing them from the workspace."), wxITEM_NORMAL);
    Menu1->Append(MenuItem22);
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Closes Monkeywrench."), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu3 = new wxMenu();
    MenuItem8 = new wxMenuItem(Menu3, idMenuCut, _("Cut\tCtrl-X"), _("Removes the selection and sends it to the clipboard."), wxITEM_NORMAL);
    Menu3->Append(MenuItem8);
    MenuItem9 = new wxMenuItem(Menu3, idMenuCopy, _("Copy\tCtrl-C"), _("Sends the selection to the clipboard."), wxITEM_NORMAL);
    Menu3->Append(MenuItem9);
    MenuItem10 = new wxMenuItem(Menu3, idMenuPaste, _("Paste\tCtrl-V"), _("Inserts the contents of the clipboard."), wxITEM_NORMAL);
    Menu3->Append(MenuItem10);
    MenuItem11 = new wxMenuItem(Menu3, idMenuDelete, _("Delete\tDelete"), _("Removes the selection."), wxITEM_NORMAL);
    Menu3->Append(MenuItem11);
    Menu3->AppendSeparator();
    MenuItem12 = new wxMenuItem(Menu3, idMenuSelectAll, _("Select All\tCtrl-A"), _("Includes all objects within the selection."), wxITEM_NORMAL);
    Menu3->Append(MenuItem12);
    MenuItem13 = new wxMenuItem(Menu3, idMenuSelectNone, _("Select None\tCtrl-D"), _("Excludes all objects from the selection."), wxITEM_NORMAL);
    Menu3->Append(MenuItem13);
    MenuBar1->Append(Menu3, _("&Edit"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Displays author information."), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[2] = { -1, 96 };
    int __wxStatusBarStyles_1[2] = { wxSB_RAISED, wxSB_NORMAL };
    StatusBar1->SetFieldsCount(2,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(2,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    ToolBar1 = new wxToolBar(this, ID_TOOLBAR1, wxDefaultPosition, wxDefaultSize, wxTB_DOCKABLE|wxTB_HORIZONTAL|wxNO_BORDER, _T("ID_TOOLBAR1"));
    ToolBarItem1 = ToolBar1->AddTool(100, _("New"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_NEW")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_NEW")),wxART_OTHER), wxITEM_NORMAL, _("New"), _("Creates a new, blank resource of your choosing: zonefile, objectdef, actordef, tileset, picfile, or soundfile."));
    ToolBarItem2 = ToolBar1->AddTool(101, _("Open"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_OPEN")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_OPEN")),wxART_OTHER), wxITEM_NORMAL, _("Open"), _("Loads a resource file from disk."));
    ToolBarItem3 = ToolBar1->AddTool(102, _("Close"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FOLDER")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FOLDER")),wxART_OTHER), wxITEM_NORMAL, _("Close"), _("Closes the current resource file, removing it from the workspace."));
    ToolBarItem4 = ToolBar1->AddTool(103, _("Save"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_SAVE")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_SAVE")),wxART_OTHER), wxITEM_NORMAL, _("Save"), _("Saves a resource file under the current filename."));
    ToolBarItem5 = ToolBar1->AddTool(104, _("Save As"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_SAVE_AS")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_SAVE_AS")),wxART_OTHER), wxITEM_NORMAL, _("Save As"), _("Saves a resource file under a new filename."));
    ToolBar1->AddSeparator();
    ToolBarItem6 = ToolBar1->AddTool(200, _("Cut"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_CUT")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_CUT")),wxART_OTHER), wxITEM_NORMAL, _("Cut"), _("Removes the selection and sends it to the clipboard."));
    ToolBarItem7 = ToolBar1->AddTool(201, _("Copy"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_COPY")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_COPY")),wxART_OTHER), wxITEM_NORMAL, _("Copy"), _("Sends the selection to the clipboard."));
    ToolBarItem8 = ToolBar1->AddTool(202, _("Paste"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_PASTE")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_PASTE")),wxART_OTHER), wxITEM_NORMAL, _("Paste"), _("Inserts the contents of the clipboard."));
    ToolBarItem9 = ToolBar1->AddTool(203, _("Delete"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_DELETE")),wxART_TOOLBAR), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_DELETE")),wxART_OTHER), wxITEM_NORMAL, _("Delete"), _("Removes the selection."));
    ToolBar1->AddSeparator();
    ToolBarItem10 = ToolBar1->AddTool(300, _("Select All"), wxNullBitmap, wxNullBitmap, wxITEM_NORMAL, _("Select All"), _("Includes all objects within the selection."));
    ToolBarItem11 = ToolBar1->AddTool(301, _("Select None"), wxNullBitmap, wxNullBitmap, wxITEM_NORMAL, _("Select None"), _("Excludes all objects from the selection."));
    ToolBar1->Realize();
    SetToolBar(ToolBar1);
    Center();

    Connect(idMenuNewZone,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MonkeywrenchFrame::OnNewZonefile);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MonkeywrenchFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MonkeywrenchFrame::OnAbout);
    //*)
}

MonkeywrenchFrame::~MonkeywrenchFrame()
{
    //(*Destroy(MonkeywrenchFrame)
    //*)
}

void MonkeywrenchFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void MonkeywrenchFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void MonkeywrenchFrame::OnNewZonefile(wxCommandEvent& event)
{
    ZonePanel* panel = new ZonePanel(MainNotebook);
    MainNotebook->AddPage(panel, _("Untitled.zf.bap"), true, -1);
}
